<!doctype html><html lang="en">
 <head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <title>CSS Extensions</title>
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <meta content="exploring" name="csswg-work-status">
  <meta content="ED" name="w3c-status">
  <meta content="This specification defines methods for authors to extend and enhance various CSS features." name="abstract">
  <link href="../default.css" rel="stylesheet" type="text/css">
  <link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<style>
  body {
    background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat;
  }
  </style>
  <link href="https://drafts.csswg.org/css-extensions" rel="canonical">
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
   regarding paragraph and lists. */
[data-md] > :first-child {
    margin-top: 0;
}
[data-md] > :last-child {
    margin-bottom: 0;
}</style>
<style>/* style-counters */

body {
    counter-reset: example figure issue;
}
.issue {
    counter-increment: issue;
}
.issue:not(.no-marker)::before {
    content: "Issue " counter(issue);
}

.example {
    counter-increment: example;
}
.example:not(.no-marker)::before {
    content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
    content: "Invalid Example" counter(example);
}

figcaption {
    counter-increment: figure;
}
figcaption:not(.no-marker)::before {
    content: "Figure " counter(figure) " ";
}</style>
<style>/* style-dfn-panel */

.dfn-panel {
    position: absolute;
    z-index: 35;
    height: auto;
    width: -webkit-fit-content;
    width: fit-content;
    max-width: 300px;
    max-height: 500px;
    overflow: auto;
    padding: 0.5em 0.75em;
    font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
    background: #DDDDDD;
    color: black;
    border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
    display: inline-block;
    position: fixed;
    left: .5em;
    bottom: 2em;
    margin: 0 auto;
    max-width: calc(100vw - 1.5em - .4em - .5em);
    max-height: 30vh;
}

.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-selflinks */

.heading, .issue, .note, .example, li, dt {
    position: relative;
}
a.self-link {
    position: absolute;
    top: 0;
    left: calc(-1 * (3.5rem - 26px));
    width: calc(3.5rem - 26px);
    height: 2em;
    text-align: center;
    border: none;
    transition: opacity .2s;
    opacity: .5;
}
a.self-link:hover {
    opacity: 1;
}
.heading > a.self-link {
    font-size: 83%;
}
li > a.self-link {
    left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
    top: auto;
    left: auto;
    opacity: 0;
    width: 1.5em;
    height: 1.5em;
    background: gray;
    color: white;
    font-style: normal;
    transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
    opacity: 1;
}
dfn > a.self-link:hover {
    color: black;
}

a.self-link::before            { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before      { content: "#"; }</style>
<style>/* style-autolinks */

.css.css, .property.property, .descriptor.descriptor {
    color: #005a9c;
    font-size: inherit;
    font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
    content: "‘";
}
.css::after, .property::after, .descriptor::after {
    content: "’";
}
.property, .descriptor {
    /* Don't wrap property and descriptor names */
    white-space: nowrap;
}
.type { /* CSS value <type> */
    font-style: italic;
}
pre .property::before, pre .property::after {
    content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
    content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
    content: "’";
}

[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
    content: "";
}

[data-link-type=element],
[data-link-type=element-attr] {
    font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
    font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after  { content: ">" }

[data-link-type=biblio] {
    white-space: pre;
}</style>
 <body class="h-entry">
  <div class="head">
   <p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
   <h1 class="p-name no-ref" id="title">CSS Extensions</h1>
   <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="1970-01-01">1 January 1970</time></span></h2>
   <details>
    <summary>Specification Metadata</summary>
    <div data-fill-with="spec-metadata">
     <dl>
      <dt>This version:
      <dd><a class="u-url" href="https://drafts.csswg.org/css-extensions">https://drafts.csswg.org/css-extensions</a>
      <dt class="editor">Editor:
      <dd class="editor p-author h-card vcard" data-editor-id="42199"><a class="p-name fn u-url url" href="http://xanthir.com/contact/">Tab Atkins</a> (<span class="p-org org">Google</span>)
      <dt>Suggest an Edit for this Spec:
      <dd><a href="https://github.com/w3c/csswg-drafts/blob/master/css-extensions-1/Overview.bs">GitHub Editor</a>
      <dt>Issue Tracking:
      <dd><a href="https://github.com/w3c/csswg-drafts/labels/css-extensions-1">GitHub Issues</a>
     </dl>
    </div>
   </details>
   <div data-fill-with="warning"></div>
   <p class="copyright" data-fill-with="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 1970 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="https://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">permissive document license</a> rules apply. </p>
   <hr title="Separator for header">
  </div>
  <div class="p-summary" data-fill-with="abstract">
   <h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
   <p>This specification defines methods for authors to extend and enhance various CSS features.</p>
    <a href="https://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, etc. 
  </div>
  <h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
  <div data-fill-with="status">
   <p> This is a public copy of the editors’ draft.
	It is provided for discussion only and may change at any moment.
	Its publication here does not imply endorsement of its contents by W3C.
	Don’t cite this document other than as work in progress. </p>
   <p> <a href="https://github.com/w3c/csswg-drafts/issues">GitHub Issues</a> are preferred for discussion of this specification.
	When filing an issue, please put the text “css-extensions” in the title,
	preferably like this:
	“[css-extensions] <i data-lt>…summary of comment…</i>”.
	All issues and comments are <a href="https://lists.w3.org/Archives/Public/public-css-archive/">archived</a>,
	and there is also a <a href="https://lists.w3.org/Archives/Public/www-style/">historical archive</a>. </p>
   <p> This document was produced by the <a href="https://www.w3.org/Style/CSS/">CSS Working Group</a>. </p>
   <p> This document was produced by a group operating under
	the <a href="https://www.w3.org/Consortium/Patent-Policy/">W3C Patent Policy</a>.
	W3C maintains a <a href="https://www.w3.org/2004/01/pp-impl/32061/status" rel="disclosure">public list of any patent disclosures</a> made in connection with the deliverables of the group;
	that page also includes instructions for disclosing a patent.
	An individual who has actual knowledge of a patent which the individual believes contains <a href="https://www.w3.org/Consortium/Patent-Policy/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://www.w3.org/Consortium/Patent-Policy/#sec-Disclosure">section 6 of the W3C Patent Policy</a>. </p>
   <p> This document is governed by the <a href="https://www.w3.org/2019/Process-20190301/" id="w3c_process_revision">1 March 2019 W3C Process Document</a>. </p>
   <p></p>
  </div>
  <div data-fill-with="at-risk"></div>
  <nav data-fill-with="table-of-contents" id="toc">
   <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
   <ol class="toc" role="directory">
    <li><a href="#intro"><span class="secno">1</span> <span class="content"> Introduction</span></a>
    <li><a href="#extension-name"><span class="secno">2</span> <span class="content"> Extension Names</span></a>
    <li>
     <a href="#custom-selectors"><span class="secno">3</span> <span class="content"> <span>Custom Selectors</span></span></a>
     <ol class="toc">
      <li><a href="#script-custom-selectors"><span class="secno">3.1</span> <span class="content"> Script-based Custom Selectors</span></a>
      <li><a href="#custom-selectors-cssom"><span class="secno">3.2</span> <span class="content"> CSSOM</span></a>
     </ol>
    <li><a href="#custom-property"><span class="secno">4</span> <span class="content"> Custom Properties</span></a>
    <li><a href="#custom-functions"><span class="secno">5</span> <span class="content"> Custom Functions</span></a>
    <li><a href="#custom-combinators"><span class="secno">6</span> <span class="content"> Custom Selector Combinators</span></a>
    <li><a href="#custom-atrules"><span class="secno">7</span> <span class="content"> Custom At-Rules</span></a>
    <li>
     <a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
     <ol class="toc">
      <li><a href="#document-conventions"><span class="secno"></span> <span class="content"> Document conventions</span></a>
      <li><a href="#conform-classes"><span class="secno"></span> <span class="content"> Conformance classes</span></a>
      <li>
       <a href="#conform-responsible"><span class="secno"></span> <span class="content"> Requirements for Responsible Implementation of CSS</span></a>
       <ol class="toc">
        <li><a href="#conform-partial"><span class="secno"></span> <span class="content"> Partial Implementations</span></a>
        <li><a href="#conform-future-proofing"><span class="secno"></span> <span class="content"> Implementations of Unstable and Proprietary Features</span></a>
        <li><a href="#conform-testing"><span class="secno"></span> <span class="content"> Implementations of CR-level Features</span></a>
       </ol>
     </ol>
    <li>
     <a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
     <ol class="toc">
      <li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
      <li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
     </ol>
    <li>
     <a href="#references"><span class="secno"></span> <span class="content">References</span></a>
     <ol class="toc">
      <li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
     </ol>
    <li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
   </ol>
  </nav>
  <main>
   <h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content"> Introduction</span><a class="self-link" href="#intro"></a></h2>
   <p>When authoring CSS,
	one often encounters significant repetition in certain features.
	For example, a given media query might be repeated in several places,
	or a selector meant to apply to all heading elements
	requires specifying <span class="css">:matches(h1, h2, h3, h4, h5, h6)</span> in every location that uses it.</p>
   <p>This repetition makes stylesheets more verbose and difficult to read,
	and also affects maintenance,
	as the author has to keep each repetition in sync when making any changes.</p>
   <p>This specification defines methods for extending several CSS features
	so that a long or repeatedly-used value can be given a short, memorable name instead,
	or a feature can be given a more complex definition controlled by a scripting language.
	This makes stylesheets easier to read,
	and more powerful in general,
	as authors can extend the feature-set of CSS themselves
	rather than waiting for standards bodies to define new features for them.</p>
   <h2 class="heading settled" data-level="2" id="extension-name"><span class="secno">2. </span><span class="content"> Extension Names</span><a class="self-link" href="#extension-name"></a></h2>
   <p>All extensions defined in this specification use a common syntax for defining their ”names”:
	the <a class="production css" data-link-type="type" href="#typedef-extension-name" id="ref-for-typedef-extension-name">&lt;extension-name></a> production.
	An <dfn class="dfn-paneled css" data-dfn-type="type" data-export id="typedef-extension-name">&lt;extension-name></dfn> is any <a data-link-type="dfn" href="https://drafts.csswg.org/css-values-3/#css-identifier" id="ref-for-css-identifier">identifier</a> that starts with two dashes (U+002D HYPHEN-MINUS),
	like <span class="css">--foo</span>, or even exotic names like <span class="css">--</span> or <span class="css">------</span>.
	The CSS language will never use identifiers of this form for any language-defined purpose,
	so it’s safe to use them for author-defined purposes
	without ever having to worry about colliding with CSS-defined names.</p>
   <h2 class="heading settled" data-level="3" id="custom-selectors"><span class="secno">3. </span><span class="content"> <dfn class="dfn-paneled" data-dfn-type="dfn" data-lt="custom selector" data-noexport id="custom-selector">Custom Selectors</dfn></span><a class="self-link" href="#custom-selectors"></a></h2>
   <p>A <dfn data-dfn-type="dfn" data-noexport id="declarative-custom-selector">declarative custom selector<a class="self-link" href="#declarative-custom-selector"></a></dfn> is defined with the <a class="css" data-link-type="maybe" href="#at-ruledef-custom-selector" id="ref-for-at-ruledef-custom-selector">@custom-selector</a> rule:</p>
<pre class="prod"><dfn class="dfn-paneled" data-dfn-type="at-rule" data-export id="at-ruledef-custom-selector">@custom-selector</dfn> = @custom-selector <a class="production" data-link-type="type" href="#typedef-custom-selector" id="ref-for-typedef-custom-selector">&lt;custom-selector></a> <a class="production" data-link-type="type" href="https://drafts.csswg.org/selectors-4/#typedef-selector-list" id="ref-for-typedef-selector-list">&lt;selector-list></a> ;
<dfn class="dfn-paneled" data-dfn-type="type" data-export id="typedef-custom-selector">&lt;custom-selector></dfn> = <a class="production" data-link-type="type" href="#typedef-custom-arg" id="ref-for-typedef-custom-arg">&lt;custom-arg></a><a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#mult-opt" id="ref-for-mult-opt">?</a> : <a class="production" data-link-type="type" href="#typedef-extension-name" id="ref-for-typedef-extension-name①">&lt;extension-name></a> [ ( <a class="production" data-link-type="type" href="#typedef-custom-arg" id="ref-for-typedef-custom-arg①">&lt;custom-arg></a><a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#mult-one-plus" id="ref-for-mult-one-plus">+</a><a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#mult-comma" id="ref-for-mult-comma">#</a><a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#mult-opt" id="ref-for-mult-opt①">?</a> ) ]<a data-link-type="grammar" href="https://drafts.csswg.org/css-values-4/#mult-opt" id="ref-for-mult-opt②">?</a> ;
<dfn class="dfn-paneled" data-dfn-type="type" data-export id="typedef-custom-arg">&lt;custom-arg></dfn> = $ <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-syntax-3/#typedef-ident-token" id="ref-for-typedef-ident-token">&lt;ident-token></a> ;
</pre>
   <p>Where there must be no whitespace
	between <code>:</code> and <a class="production css" data-link-type="type" href="#typedef-extension-name" id="ref-for-typedef-extension-name②">&lt;extension-name></a> or between <code>$</code> and <a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-syntax-3/#typedef-ident-token" id="ref-for-typedef-ident-token①">&lt;ident-token></a> in the above definitions.</p>
   <div class="issue" id="issue-4726afee">
    <a class="self-link" href="#issue-4726afee"></a> Simple things are easy: 
<pre>@custom-selector :--heading {
  expansion: h1, h2, h3, h4, h5, h6;
}
</pre>
    <p>More complicated things are possible:</p>
<pre>// Arguments are specified with $foo.
// An arg before the pseudo-class captures the rest of the compound selector.
@custom-selector $rest:--n-siblings($n, $sel) {
  specificity: $sel;
  // assumes $sel is a selector, parses it and uses its specificity
  // otherwise, specificity is [0,1,0]
  expansion: $rest:nth-child(1 of $sel):nth-last-child($n of $sel),
    :nth-child(1 of $sel):nth-last-child($n of $sel) ~ $rest;
}
</pre>
   </div>
   <p>This defines a <a data-link-type="dfn" href="#custom-selector" id="ref-for-custom-selector">custom selector</a> which is written as a <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#pseudo-class" id="ref-for-pseudo-class">pseudo-class</a> with the given <a class="production css" data-link-type="type" href="#typedef-extension-name" id="ref-for-typedef-extension-name③">&lt;extension-name></a>,
	and represents a <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/selectors-4/#selectordef-matches" id="ref-for-selectordef-matches">:matches()</a> selector using the provided <a class="production css" data-link-type="type" href="https://drafts.csswg.org/selectors-4/#typedef-selector-list" id="ref-for-typedef-selector-list①">&lt;selector-list></a> as its argument.</p>
   <div class="example" id="example-c8fe672b">
    <a class="self-link" href="#example-c8fe672b"></a> For example, if an author wanted to easily refer to all heading elements in their HTML document,
		they could create an alias: 
<pre>@custom-selector :--heading h1, h2, h3, h4, h5, h6;

:--heading { /* styles for all headings */ }
:--heading + p { /* more styles */ }
/* etc */
</pre>
   </div>
   <h3 class="heading settled" data-level="3.1" id="script-custom-selectors"><span class="secno">3.1. </span><span class="content"> Script-based Custom Selectors</span><a class="self-link" href="#script-custom-selectors"></a></h3>
   <div class="issue" id="issue-9e18175f">
    <a class="self-link" href="#issue-9e18175f"></a> This one’s more complicated than MQs.
		Brian Kardell came up with a good proposal for evaluating selectors as JS functions that return a boolean,
		which had decent performance characteristics by specifying the qualities of the element it was based on
		(which determined when it would be called). 
<pre>&lt;script>
CSS.customSelector.set("_foo",
                     {"predicate": function(el){...},
                       "matches": "a"});
&lt;/script>
</pre>
    <p>"matches" is an optional selector specifying what subset of elements the custom selector is valid for.
		The selector is automatically false for elements that don’t match,
		and the predicate isn’t called.</p>
    <p>By default, the predicate is called whenever there’s a mutation in an element that matches the "matches" selector,
		or one of its descendants.</p>
    <p>You should be able to suppress the auto-calling,
		and be able to trigger the predicate to run manually.
		That way you can use mutation listeners manually to only call the predicate when necessary.</p>
    <p>We should probably offer some sugar for filtering the list of mutations that trigger the predicate to be called.
		Maybe just a list of attributes that you’ll be caring about?  And/or tagnames?</p>
    <p>Maybe let the pseudo-class also accept an argument,
		and pass it (as a serialized string) as a second argument to the predicate. <span class="css">:_foo</span> would pass <code>null</code>,
		while <span class="css">:_foo()</span> would pass <code>""</code>.</p>
   </div>
   <h3 class="heading settled" data-level="3.2" id="custom-selectors-cssom"><span class="secno">3.2. </span><span class="content"> CSSOM</span><a class="self-link" href="#custom-selectors-cssom"></a></h3>
   <p class="issue" id="issue-cb6e966f"><a class="self-link" href="#issue-cb6e966f"></a> Fill in. </p>
   <h2 class="heading settled" data-level="4" id="custom-property"><span class="secno">4. </span><span class="content"> Custom Properties</span><a class="self-link" href="#custom-property"></a></h2>
   <div class="issue" id="issue-c207e118">
    <a class="self-link" href="#issue-c207e118"></a> Need to more fully support Custom Properties
		(and eventually remove them from the variable spec entirely, since they’ll be defined here). 
    <p>By default, custom properties are optimized for use as <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-variables-1/#funcdef-var" id="ref-for-funcdef-var">var()</a> values—<wbr>they inherit,
		have an empty initial value,
		don’t do any syntax checking,
		and don’t animate.
		All of these should be adjustable somehow.</p>
<pre>@custom-property --foo {
  scope: [ inherit | local ];
  initial: <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value" id="ref-for-typedef-declaration-value">&lt;declaration-value></a>*;
  value: <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-values-3/#length-value" id="ref-for-length-value" title="Expands to: em | vb | ch | cm | vh | vi | in | ex | vw | ic | pt | px | lh | pc | rem | rlh | vmax | advance measure | vmin | mm | cap | q">&lt;length></a> <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-values-3/#length-value" id="ref-for-length-value①" title="Expands to: em | vb | ch | cm | vh | vi | in | ex | vw | ic | pt | px | lh | pc | rem | rlh | vmax | advance measure | vmin | mm | cap | q">&lt;length></a> <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-color-3/#valuea-def-color" id="ref-for-valuea-def-color" title="Expands to: indigo | gold | firebrick | indianred | yellow | darkolivegreen | darkseagreen | slategrey | darkslategrey | mediumvioletred | mediumorchid | transparent | chartreuse | mediumslateblue | black | springgreen | crimson | lightsalmon | brown | turquoise | olivedrab | cyan | silver | skyblue | gray | darkturquoise | goldenrod | darkgreen | darkviolet | darkgray | lightpink | teal | darkmagenta | lightgoldenrodyellow | lavender | yellowgreen | thistle | violet | navy | dimgrey | orchid | blue | ghostwhite | honeydew | cornflowerblue | darkblue | darkkhaki | mediumpurple | cornsilk | red | bisque | slategray | darkcyan | khaki | wheat | deepskyblue | rebeccapurple | darkred | steelblue | aliceblue | lightslategrey | gainsboro | mediumturquoise | floralwhite | coral | purple | lightgrey | lightcyan | darksalmon | beige | azure | lightsteelblue | oldlace | greenyellow | royalblue | lightseagreen | mistyrose | sienna | lightcoral | orangered | navajowhite | lime | palegreen | burlywood | seashell | mediumspringgreen | fuchsia | papayawhip | blanchedalmond | peru | aquamarine | white | darkslategray | tomato | ivory | dodgerblue | currentcolor | lemonchiffon | chocolate | orange | forestgreen | darkgrey | olive | mintcream | antiquewhite | darkorange | cadetblue | moccasin | limegreen | saddlebrown | grey | darkslateblue | lightskyblue | deeppink | plum | aqua | darkgoldenrod | maroon | sandybrown | magenta | tan | rosybrown | pink | lightblue | palevioletred | mediumseagreen | slateblue | dimgray | powderblue | seagreen | snow | mediumblue | midnightblue | paleturquoise | palegoldenrod | whitesmoke | darkorchid | salmon | lightslategray | lawngreen | lightgreen | lightgray | hotpink | lightyellow | lavenderblush | linen | mediumaquamarine | green | blueviolet | peachpuff">&lt;color></a>;
  /* Literally, define a simplistic definition syntax.
     OR FULL CSS PROPERTY GRAMMAR?!? */
}
</pre>
    <p>If you provide a "value" field with animatable types,
		we can animate in the most direct fashion automatically.
		We could also let you hook into that:
		you register a callback,
		and whenever a property starts animating,
		we call it with the starting and ending values.
		You have to return a function which takes a progress value (between 0 and 1)
		and returns a value for your property;
		we’ll call it as we animate the value.
		(How can we hook into Web Anim here? Can you just return an Animation object?)</p>
    <p>Do we need a hook for computed values?  Interesting.
		We could just hand your callback a set of property values for the element and its parent (maybe siblings, if you ask for it?),
		and you can return a new value for the property.
		This is probably an advanced feature for a later date.</p>
    <p>Definitely need a way to listen for elements receiving and changing property values,
		so you can efficiently polyfill things and make your own properties.
		Unsure how it would look at the moment.</p>
   </div>
   <h2 class="heading settled" data-level="5" id="custom-functions"><span class="secno">5. </span><span class="content"> Custom Functions</span><a class="self-link" href="#custom-functions"></a></h2>
   <div class="issue" id="issue-d6d2d4d8">
    <a class="self-link" href="#issue-d6d2d4d8"></a> Interesting possibilities here.
		Definitely need some way to define custom functions in CSS.
		This would, for example, let people define whatever color function they want,
		such as implementing the <a href="http://www.boronine.com/husl/">HUSL</a> color space. 
    <p>Definitely need a JS interface.
		What options are needed?</p>
    <p>Call time/frequency:</p>
    <ul>
     <li> Default should probably treat the function as a preprocessor,
				calling the JS function once per instance in the stylesheet
				and substituting in the returned value. 
     <li> Should probably have an option to allow calling per element/instance combo, too.
				Gets called more as match results change. 
    </ul>
    <p>We can take some cues from my thoughts on a random() function.
		It needs per-instance,
		per-element&amp;instance,
		and per "identifier", so you can reuse the same value in multiple spots.
		That last one can probably be handled manually by the JS,
		so we don’t have to privilege a particular argument as an identifier.</p>
    <p>We’d need to provide the context in which it’s used.
		Which property, for example.
		Should we allow them to be used in other places,
		or should we just define more contextual locations as we go?
		That is, should we allow custom-defined functions in @supports with this API,
		or should we add a <code>.customSupports</code> map?
		I suspect that individual cases will have their own useful contextual information,
		so it’s better to specialize each instance of custom functions.</p>
    <p>How much can we do in pure CSS?
		Being able to substitute values depending on MQs or support queries would be useful.
		(However, we can do that much just by using custom properties and <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-variables-1/#funcdef-var" id="ref-for-funcdef-var①">var()</a>.)
		To get *real* use out of it, though, I suspect we’d need fuller support for conditionals,
		likely in the form of SASS’s <span class="css">@if</span> or something similar.</p>
   </div>
   <h2 class="heading settled" data-level="6" id="custom-combinators"><span class="secno">6. </span><span class="content"> Custom Selector Combinators</span><a class="self-link" href="#custom-combinators"></a></h2>
   <div class="issue" id="issue-9061f103">
    <a class="self-link" href="#issue-9061f103"></a> Selectors are made of two pieces:
		simple selectors,
		and combinators.
		We should allow custom combinators too. 
    <p>This is JS-only, because it’s transforming elements, not filtering them,
		and you can’t express any useful transformations in pure CSS.</p>
    <p>You provide a function which,
		when given an element,
		produces a list of zero or more elements.</p>
    <p>For examples, with <span class="css">div /--foo/ span</span>,
		the CSS engine will match the first part of the selector
		and find all the div elements.
		It passes that list to the function registered for the --foo combinator,
		and expects to get a new list of elements returned.
		It then continues on its way,
		filtering that list to include only span elements, etc.</p>
    <p>A child combinator would be something like:</p>
<pre>CSS.customCombinator.set("--child", function(el) {
    return el.children;
  });
</pre>
    <p>Then <span class="css">div /--child/ span</span> would be identical to <span class="css">div > span</span>.</p>
    <p>If we generalize a selector with a custom combinator to <span class="css">A /--custom/ B</span>,
		then the UA would automatically call the --custom function
		whenever new elements match <span class="css">A</span>.
		If elements stop matching <span class="css">A</span>,
		it won’t bother;
		it’ll just drop them from the result.</p>
    <p>Alternately, the function could take a list of elements
		(all the elements matching <span class="css">A</span>)
		and return a new list of elements.
		This would be a bit more complicated for the author,
		but would allow more variety in the types of combinators that could be defined,
		as you could define things that depend on the entire set of matched elements.
		For example, you could define <span class="css">A /nth 1/ B</span> to give only the first element from the set of <span class="css">A</span> matches.</p>
    <p>(Maybe we allow both variants,
		since the per-element one is easier to optimize and program against,
		but the per-set one allows some useful stuff.)</p>
    <p>Similarly to custom pseudo-classes,
		we’d allow arguments,
		with them parsed eagerly per-instance
		and passed to the combinator function.</p>
    <p>If we do the per-element combinator function,
		we could potentially cache the results,
		so that it never needs to be called again for the same element.
		Possibly have a flag that turns off this behavior,
		so that you’re guaranteed to be called again.</p>
   </div>
   <h2 class="heading settled" data-level="7" id="custom-atrules"><span class="secno">7. </span><span class="content"> Custom At-Rules</span><a class="self-link" href="#custom-atrules"></a></h2>
   <div class="issue" id="issue-329c3458">
    <a class="self-link" href="#issue-329c3458"></a> This one’s even less developed,
		but it would be interesting to allow custom at-rules as well.
		It’s definitely pure-JS as well. 
    <p>Unsure exactly what’s best here.
		Possibly register a callback per rule,
		which is called with the prelude/contents of the at-rule?</p>
    <p>Should we do the callback approach,
		or just maintain a list of custom at-rules
		and let scripts parse them themselves?
		Unfortunately, the latter means we’d have to have a special mechanism to alert scripts
		when new at-rules get added or removed.</p>
    <p>For a lot of these at-rules, we may want a way to know when they’re "applied"—<wbr>when, according to the built-in at-rules like @media and @supports,
		the rule would be applied.</p>
   </div>
  </main>
  <h2 class="no-ref no-num heading settled" id="conformance"><span class="content"> Conformance</span><a class="self-link" href="#conformance"></a></h2>
  <h3 class="heading settled" id="document-conventions"><span class="content"> Document conventions</span><a class="self-link" href="#document-conventions"></a></h3>
  <p>Conformance requirements are expressed with a combination of
	descriptive assertions and RFC 2119 terminology. The key words “MUST”,
	“MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
	“RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
	document are to be interpreted as described in RFC 2119.
	However, for readability, these words do not appear in all uppercase
	letters in this specification. </p>
  <p>All of the text of this specification is normative except sections
	explicitly marked as non-normative, examples, and notes. <a data-link-type="biblio" href="#biblio-rfc2119">[RFC2119]</a> </p>
  <p>Examples in this specification are introduced with the words “for example”
	or are set apart from the normative text with <code>class="example"</code>,
	like this: </p>
  <div class="example" id="example-ae2b6bc0">
   <a class="self-link" href="#example-ae2b6bc0"></a> 
   <p>This is an example of an informative example. </p>
  </div>
  <p>Informative notes begin with the word “Note” and are set apart from the
	normative text with <code>class="note"</code>, like this: </p>
  <p class="note" role="note">Note, this is an informative note. </p>
  <p>Advisements are normative sections styled to evoke special attention and are
	set apart from other normative text with <code>&lt;strong class="advisement"></code>, like
	this: <strong class="advisement"> UAs MUST provide an accessible alternative. </strong> </p>
  <h3 class="heading settled" id="conform-classes"><span class="content"> Conformance classes</span><a class="self-link" href="#conform-classes"></a></h3>
  <p>Conformance to this specification
	is defined for three conformance classes: </p>
  <dl>
   <dt>style sheet 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#style-sheet">CSS
			style sheet</a>. 
   <dt>renderer 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that interprets the semantics of a style sheet and renders
			documents that use them. 
   <dt>authoring tool 
   <dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that writes a style sheet. 
  </dl>
  <p>A style sheet is conformant to this specification
	if all of its statements that use syntax defined in this module are valid
	according to the generic CSS grammar and the individual grammars of each
	feature defined in this module. </p>
  <p>A renderer is conformant to this specification
	if, in addition to interpreting the style sheet as defined by the
	appropriate specifications, it supports all the features defined
	by this specification by parsing them correctly
	and rendering the document accordingly. However, the inability of a
	UA to correctly render a document due to limitations of the device
	does not make the UA non-conformant. (For example, a UA is not
	required to render color on a monochrome monitor.) </p>
  <p>An authoring tool is conformant to this specification
	if it writes style sheets that are syntactically correct according to the
	generic CSS grammar and the individual grammars of each feature in
	this module, and meet all other conformance requirements of style sheets
	as described in this module. </p>
  <h3 class="heading settled" id="conform-responsible"><span class="content"> Requirements for Responsible Implementation of CSS</span><a class="self-link" href="#conform-responsible"></a></h3>
  <p>The following sections define several conformance requirements
		for implementing CSS responsibly,
		in a way that promotes interoperability in the present and future. </p>
  <h4 class="heading settled" id="conform-partial"><span class="content"> Partial Implementations</span><a class="self-link" href="#conform-partial"></a></h4>
  <p>So that authors can exploit the forward-compatible parsing rules to assign fallback values, <strong>CSS renderers <em>must</em> treat as invalid
		(and <a href="http://www.w3.org/TR/CSS2/conform.html#ignore">ignore as appropriate</a>)
		any at-rules, properties, property values, keywords, and other syntactic constructs
		for which they have no usable level of support</strong>.
		In particular, user agents <em>must not</em> selectively ignore
		unsupported property values and honor supported values in a single multi-value property declaration:
		if any value is considered invalid (as unsupported values must be),
		CSS requires that the entire declaration be ignored. </p>
  <h4 class="heading settled" id="conform-future-proofing"><span class="content"> Implementations of Unstable and Proprietary Features</span><a class="self-link" href="#conform-future-proofing"></a></h4>
  <p>To avoid clashes with future stable CSS features,
		the CSSWG recommends <a href="http://www.w3.org/TR/CSS/#future-proofing">following best practices</a> for the implementation of <a href="http://www.w3.org/TR/CSS/#unstable">unstable</a> features and <a href="http://www.w3.org/TR/CSS/#proprietary-extension">proprietary extensions</a> to CSS. </p>
  <h4 class="heading settled" id="conform-testing"><span class="content"> Implementations of CR-level Features</span><a class="self-link" href="#conform-testing"></a></h4>
  <p>Once a specification reaches the Candidate Recommendation stage,
		implementers should release an <a data-link-type="dfn" href="http://www.w3.org/TR/CSS/#vendor-prefix">unprefixed</a> implementation
		of any CR-level feature they can demonstrate
		to be correctly implemented according to spec,
		and should avoid exposing a prefixed variant of that feature. </p>
  <p>To establish and maintain the interoperability of CSS across
		implementations, the CSS Working Group requests that non-experimental
		CSS renderers submit an implementation report (and, if necessary, the
		testcases used for that implementation report) to the W3C before
		releasing an unprefixed implementation of any CSS features. Testcases
		submitted to W3C are subject to review and correction by the CSS
		Working Group. </p>
  <p>
   Further information on submitting testcases and implementation reports
		can be found from on the CSS Working Group’s website at <a href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
		Questions should be directed to the <a href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a> mailing list. 
<script src="https://www.w3.org/scripts/TR/2016/fixup.js"></script>
  </p>
  <h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
  <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span><a class="self-link" href="#index-defined-here"></a></h3>
  <ul class="index">
   <li><a href="#typedef-custom-arg">&lt;custom-arg></a><span>, in §3</span>
   <li><a href="#typedef-custom-selector">&lt;custom-selector></a><span>, in §3</span>
   <li><a href="#custom-selector">custom selector</a><span>, in §3</span>
   <li><a href="#at-ruledef-custom-selector">@custom-selector</a><span>, in §3</span>
   <li><a href="#declarative-custom-selector">declarative custom selector</a><span>, in §3</span>
   <li><a href="#typedef-extension-name">&lt;extension-name></a><span>, in §2</span>
  </ul>
  <aside class="dfn-panel" data-for="term-for-valuea-def-color">
   <a href="https://drafts.csswg.org/css-color-3/#valuea-def-color">https://drafts.csswg.org/css-color-3/#valuea-def-color</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-valuea-def-color">4. 
Custom Properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-typedef-declaration-value">
   <a href="https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value">https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-declaration-value">4. 
Custom Properties</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-typedef-ident-token">
   <a href="https://drafts.csswg.org/css-syntax-3/#typedef-ident-token">https://drafts.csswg.org/css-syntax-3/#typedef-ident-token</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-ident-token">3. 
Custom Selectors</a> <a href="#ref-for-typedef-ident-token①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-length-value">
   <a href="https://drafts.csswg.org/css-values-3/#length-value">https://drafts.csswg.org/css-values-3/#length-value</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-length-value">4. 
Custom Properties</a> <a href="#ref-for-length-value①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-css-identifier">
   <a href="https://drafts.csswg.org/css-values-3/#css-identifier">https://drafts.csswg.org/css-values-3/#css-identifier</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-css-identifier">2. 
Extension Names</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-mult-comma">
   <a href="https://drafts.csswg.org/css-values-4/#mult-comma">https://drafts.csswg.org/css-values-4/#mult-comma</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-mult-comma">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-mult-one-plus">
   <a href="https://drafts.csswg.org/css-values-4/#mult-one-plus">https://drafts.csswg.org/css-values-4/#mult-one-plus</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-mult-one-plus">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-mult-opt">
   <a href="https://drafts.csswg.org/css-values-4/#mult-opt">https://drafts.csswg.org/css-values-4/#mult-opt</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-mult-opt">3. 
Custom Selectors</a> <a href="#ref-for-mult-opt①">(2)</a> <a href="#ref-for-mult-opt②">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-funcdef-var">
   <a href="https://drafts.csswg.org/css-variables-1/#funcdef-var">https://drafts.csswg.org/css-variables-1/#funcdef-var</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-funcdef-var">4. 
Custom Properties</a>
    <li><a href="#ref-for-funcdef-var①">5. 
Custom Functions</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-selectordef-matches">
   <a href="https://drafts.csswg.org/selectors-4/#selectordef-matches">https://drafts.csswg.org/selectors-4/#selectordef-matches</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-selectordef-matches">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-typedef-selector-list">
   <a href="https://drafts.csswg.org/selectors-4/#typedef-selector-list">https://drafts.csswg.org/selectors-4/#typedef-selector-list</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-selector-list">3. 
Custom Selectors</a> <a href="#ref-for-typedef-selector-list①">(2)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="term-for-pseudo-class">
   <a href="https://drafts.csswg.org/selectors-4/#pseudo-class">https://drafts.csswg.org/selectors-4/#pseudo-class</a><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-pseudo-class">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
  <ul class="index">
   <li>
    <a data-link-type="biblio">[css-color-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-valuea-def-color" style="color:initial">&lt;color></span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-syntax-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-typedef-declaration-value" style="color:initial">&lt;declaration-value></span>
     <li><span class="dfn-paneled" id="term-for-typedef-ident-token" style="color:initial">&lt;ident-token></span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-values-3]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-length-value" style="color:initial">&lt;length></span>
     <li><span class="dfn-paneled" id="term-for-css-identifier" style="color:initial">identifier</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-values-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-mult-comma" style="color:initial">#</span>
     <li><span class="dfn-paneled" id="term-for-mult-one-plus" style="color:initial">+</span>
     <li><span class="dfn-paneled" id="term-for-mult-opt" style="color:initial">?</span>
    </ul>
   <li>
    <a data-link-type="biblio">[css-variables-1]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-funcdef-var" style="color:initial">var()</span>
    </ul>
   <li>
    <a data-link-type="biblio">[selectors-4]</a> defines the following terms:
    <ul>
     <li><span class="dfn-paneled" id="term-for-selectordef-matches" style="color:initial">:matches()</span>
     <li><span class="dfn-paneled" id="term-for-typedef-selector-list" style="color:initial">&lt;selector-list></span>
     <li><span class="dfn-paneled" id="term-for-pseudo-class" style="color:initial">pseudo-class</span>
    </ul>
  </ul>
  <h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
  <h3 class="no-num no-ref heading settled" id="normative"><span class="content">Normative References</span><a class="self-link" href="#normative"></a></h3>
  <dl>
   <dt id="biblio-css-color-3">[CSS-COLOR-3]
   <dd>Tantek Çelik; Chris Lilley; David Baron. <a href="https://www.w3.org/TR/css-color-3/">CSS Color Module Level 3</a>. 19 June 2018. REC. URL: <a href="https://www.w3.org/TR/css-color-3/">https://www.w3.org/TR/css-color-3/</a>
   <dt id="biblio-css-syntax-3">[CSS-SYNTAX-3]
   <dd>Tab Atkins Jr.; Simon Sapin. <a href="https://www.w3.org/TR/css-syntax-3/">CSS Syntax Module Level 3</a>. 20 February 2014. CR. URL: <a href="https://www.w3.org/TR/css-syntax-3/">https://www.w3.org/TR/css-syntax-3/</a>
   <dt id="biblio-css-values-3">[CSS-VALUES-3]
   <dd>Tab Atkins Jr.; Elika Etemad. <a href="https://www.w3.org/TR/css-values-3/">CSS Values and Units Module Level 3</a>. 31 January 2019. CR. URL: <a href="https://www.w3.org/TR/css-values-3/">https://www.w3.org/TR/css-values-3/</a>
   <dt id="biblio-css-values-4">[CSS-VALUES-4]
   <dd>Tab Atkins Jr.; Elika Etemad. <a href="https://www.w3.org/TR/css-values-4/">CSS Values and Units Module Level 4</a>. 31 January 2019. WD. URL: <a href="https://www.w3.org/TR/css-values-4/">https://www.w3.org/TR/css-values-4/</a>
   <dt id="biblio-css-variables-1">[CSS-VARIABLES-1]
   <dd>Tab Atkins Jr.. <a href="https://www.w3.org/TR/css-variables-1/">CSS Custom Properties for Cascading Variables Module Level 1</a>. 3 December 2015. CR. URL: <a href="https://www.w3.org/TR/css-variables-1/">https://www.w3.org/TR/css-variables-1/</a>
   <dt id="biblio-rfc2119">[RFC2119]
   <dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
   <dt id="biblio-selectors-4">[SELECTORS-4]
   <dd>Elika Etemad; Tab Atkins Jr.. <a href="https://www.w3.org/TR/selectors-4/">Selectors Level 4</a>. 21 November 2018. WD. URL: <a href="https://www.w3.org/TR/selectors-4/">https://www.w3.org/TR/selectors-4/</a>
  </dl>
  <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content">Issues Index</span><a class="self-link" href="#issues-index"></a></h2>
  <div style="counter-reset:issue">
   <div class="issue">
     Simple things are easy: 
<pre>@custom-selector :--heading {
  expansion: h1, h2, h3, h4, h5, h6;
}
</pre>
    <p>More complicated things are possible:</p>
<pre>// Arguments are specified with $foo.
// An arg before the pseudo-class captures the rest of the compound selector.
@custom-selector $rest:--n-siblings($n, $sel) {
  specificity: $sel;
  // assumes $sel is a selector, parses it and uses its specificity
  // otherwise, specificity is [0,1,0]
  expansion: $rest:nth-child(1 of $sel):nth-last-child($n of $sel),
    :nth-child(1 of $sel):nth-last-child($n of $sel) ~ $rest;
}
</pre>
     <a href="#issue-4726afee"> ↵ </a>
   </div>
   <div class="issue">
     This one’s more complicated than MQs.
		Brian Kardell came up with a good proposal for evaluating selectors as JS functions that return a boolean,
		which had decent performance characteristics by specifying the qualities of the element it was based on
		(which determined when it would be called). 
<pre>&lt;script>
CSS.customSelector.set("_foo",
                     {"predicate": function(el){...},
                       "matches": "a"});
&lt;/script>
</pre>
    <p>"matches" is an optional selector specifying what subset of elements the custom selector is valid for.
		The selector is automatically false for elements that don’t match,
		and the predicate isn’t called.</p>
    <p>By default, the predicate is called whenever there’s a mutation in an element that matches the "matches" selector,
		or one of its descendants.</p>
    <p>You should be able to suppress the auto-calling,
		and be able to trigger the predicate to run manually.
		That way you can use mutation listeners manually to only call the predicate when necessary.</p>
    <p>We should probably offer some sugar for filtering the list of mutations that trigger the predicate to be called.
		Maybe just a list of attributes that you’ll be caring about?  And/or tagnames?</p>
    <p>Maybe let the pseudo-class also accept an argument,
		and pass it (as a serialized string) as a second argument to the predicate. <span class="css">:_foo</span> would pass <code>null</code>,
		while <span class="css">:_foo()</span> would pass <code>""</code>.</p>
     <a href="#issue-9e18175f"> ↵ </a>
   </div>
   <div class="issue"> Fill in. <a href="#issue-cb6e966f"> ↵ </a></div>
   <div class="issue">
     Need to more fully support Custom Properties
		(and eventually remove them from the variable spec entirely, since they’ll be defined here). 
    <p>By default, custom properties are optimized for use as <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-variables-1/#funcdef-var">var()</a> values—<wbr>they inherit,
		have an empty initial value,
		don’t do any syntax checking,
		and don’t animate.
		All of these should be adjustable somehow.</p>
<pre>@custom-property --foo {
  scope: [ inherit | local ];
  initial: <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value">&lt;declaration-value></a>*;
  value: <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-values-3/#length-value" title="Expands to: em | vb | ch | cm | vh | vi | in | ex | vw | ic | pt | px | lh | pc | rem | rlh | vmax | advance measure | vmin | mm | cap | q">&lt;length></a> <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-values-3/#length-value" title="Expands to: em | vb | ch | cm | vh | vi | in | ex | vw | ic | pt | px | lh | pc | rem | rlh | vmax | advance measure | vmin | mm | cap | q">&lt;length></a> <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-color-3/#valuea-def-color" title="Expands to: indigo | gold | firebrick | indianred | yellow | darkolivegreen | darkseagreen | slategrey | darkslategrey | mediumvioletred | mediumorchid | transparent | chartreuse | mediumslateblue | black | springgreen | crimson | lightsalmon | brown | turquoise | olivedrab | cyan | silver | skyblue | gray | darkturquoise | goldenrod | darkgreen | darkviolet | darkgray | lightpink | teal | darkmagenta | lightgoldenrodyellow | lavender | yellowgreen | thistle | violet | navy | dimgrey | orchid | blue | ghostwhite | honeydew | cornflowerblue | darkblue | darkkhaki | mediumpurple | cornsilk | red | bisque | slategray | darkcyan | khaki | wheat | deepskyblue | rebeccapurple | darkred | steelblue | aliceblue | lightslategrey | gainsboro | mediumturquoise | floralwhite | coral | purple | lightgrey | lightcyan | darksalmon | beige | azure | lightsteelblue | oldlace | greenyellow | royalblue | lightseagreen | mistyrose | sienna | lightcoral | orangered | navajowhite | lime | palegreen | burlywood | seashell | mediumspringgreen | fuchsia | papayawhip | blanchedalmond | peru | aquamarine | white | darkslategray | tomato | ivory | dodgerblue | currentcolor | lemonchiffon | chocolate | orange | forestgreen | darkgrey | olive | mintcream | antiquewhite | darkorange | cadetblue | moccasin | limegreen | saddlebrown | grey | darkslateblue | lightskyblue | deeppink | plum | aqua | darkgoldenrod | maroon | sandybrown | magenta | tan | rosybrown | pink | lightblue | palevioletred | mediumseagreen | slateblue | dimgray | powderblue | seagreen | snow | mediumblue | midnightblue | paleturquoise | palegoldenrod | whitesmoke | darkorchid | salmon | lightslategray | lawngreen | lightgreen | lightgray | hotpink | lightyellow | lavenderblush | linen | mediumaquamarine | green | blueviolet | peachpuff">&lt;color></a>;
  /* Literally, define a simplistic definition syntax.
     OR FULL CSS PROPERTY GRAMMAR?!? */
}
</pre>
    <p>If you provide a "value" field with animatable types,
		we can animate in the most direct fashion automatically.
		We could also let you hook into that:
		you register a callback,
		and whenever a property starts animating,
		we call it with the starting and ending values.
		You have to return a function which takes a progress value (between 0 and 1)
		and returns a value for your property;
		we’ll call it as we animate the value.
		(How can we hook into Web Anim here? Can you just return an Animation object?)</p>
    <p>Do we need a hook for computed values?  Interesting.
		We could just hand your callback a set of property values for the element and its parent (maybe siblings, if you ask for it?),
		and you can return a new value for the property.
		This is probably an advanced feature for a later date.</p>
    <p>Definitely need a way to listen for elements receiving and changing property values,
		so you can efficiently polyfill things and make your own properties.
		Unsure how it would look at the moment.</p>
     <a href="#issue-c207e118"> ↵ </a>
   </div>
   <div class="issue">
     Interesting possibilities here.
		Definitely need some way to define custom functions in CSS.
		This would, for example, let people define whatever color function they want,
		such as implementing the <a href="http://www.boronine.com/husl/">HUSL</a> color space. 
    <p>Definitely need a JS interface.
		What options are needed?</p>
    <p>Call time/frequency:</p>
    <ul>
     <li> Default should probably treat the function as a preprocessor,
				calling the JS function once per instance in the stylesheet
				and substituting in the returned value. 
     <li> Should probably have an option to allow calling per element/instance combo, too.
				Gets called more as match results change. 
    </ul>
    <p>We can take some cues from my thoughts on a random() function.
		It needs per-instance,
		per-element&amp;instance,
		and per "identifier", so you can reuse the same value in multiple spots.
		That last one can probably be handled manually by the JS,
		so we don’t have to privilege a particular argument as an identifier.</p>
    <p>We’d need to provide the context in which it’s used.
		Which property, for example.
		Should we allow them to be used in other places,
		or should we just define more contextual locations as we go?
		That is, should we allow custom-defined functions in @supports with this API,
		or should we add a <code>.customSupports</code> map?
		I suspect that individual cases will have their own useful contextual information,
		so it’s better to specialize each instance of custom functions.</p>
    <p>How much can we do in pure CSS?
		Being able to substitute values depending on MQs or support queries would be useful.
		(However, we can do that much just by using custom properties and <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-variables-1/#funcdef-var">var()</a>.)
		To get *real* use out of it, though, I suspect we’d need fuller support for conditionals,
		likely in the form of SASS’s <span class="css">@if</span> or something similar.</p>
     <a href="#issue-d6d2d4d8"> ↵ </a>
   </div>
   <div class="issue">
     Selectors are made of two pieces:
		simple selectors,
		and combinators.
		We should allow custom combinators too. 
    <p>This is JS-only, because it’s transforming elements, not filtering them,
		and you can’t express any useful transformations in pure CSS.</p>
    <p>You provide a function which,
		when given an element,
		produces a list of zero or more elements.</p>
    <p>For examples, with <span class="css">div /--foo/ span</span>,
		the CSS engine will match the first part of the selector
		and find all the div elements.
		It passes that list to the function registered for the --foo combinator,
		and expects to get a new list of elements returned.
		It then continues on its way,
		filtering that list to include only span elements, etc.</p>
    <p>A child combinator would be something like:</p>
<pre>CSS.customCombinator.set("--child", function(el) {
    return el.children;
  });
</pre>
    <p>Then <span class="css">div /--child/ span</span> would be identical to <span class="css">div > span</span>.</p>
    <p>If we generalize a selector with a custom combinator to <span class="css">A /--custom/ B</span>,
		then the UA would automatically call the --custom function
		whenever new elements match <span class="css">A</span>.
		If elements stop matching <span class="css">A</span>,
		it won’t bother;
		it’ll just drop them from the result.</p>
    <p>Alternately, the function could take a list of elements
		(all the elements matching <span class="css">A</span>)
		and return a new list of elements.
		This would be a bit more complicated for the author,
		but would allow more variety in the types of combinators that could be defined,
		as you could define things that depend on the entire set of matched elements.
		For example, you could define <span class="css">A /nth 1/ B</span> to give only the first element from the set of <span class="css">A</span> matches.</p>
    <p>(Maybe we allow both variants,
		since the per-element one is easier to optimize and program against,
		but the per-set one allows some useful stuff.)</p>
    <p>Similarly to custom pseudo-classes,
		we’d allow arguments,
		with them parsed eagerly per-instance
		and passed to the combinator function.</p>
    <p>If we do the per-element combinator function,
		we could potentially cache the results,
		so that it never needs to be called again for the same element.
		Possibly have a flag that turns off this behavior,
		so that you’re guaranteed to be called again.</p>
     <a href="#issue-9061f103"> ↵ </a>
   </div>
   <div class="issue">
     This one’s even less developed,
		but it would be interesting to allow custom at-rules as well.
		It’s definitely pure-JS as well. 
    <p>Unsure exactly what’s best here.
		Possibly register a callback per rule,
		which is called with the prelude/contents of the at-rule?</p>
    <p>Should we do the callback approach,
		or just maintain a list of custom at-rules
		and let scripts parse them themselves?
		Unfortunately, the latter means we’d have to have a special mechanism to alert scripts
		when new at-rules get added or removed.</p>
    <p>For a lot of these at-rules, we may want a way to know when they’re "applied"—<wbr>when, according to the built-in at-rules like @media and @supports,
		the rule would be applied.</p>
     <a href="#issue-329c3458"> ↵ </a>
   </div>
  </div>
  <aside class="dfn-panel" data-for="typedef-extension-name">
   <b><a href="#typedef-extension-name">#typedef-extension-name</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-extension-name">2. 
Extension Names</a>
    <li><a href="#ref-for-typedef-extension-name①">3. 
Custom Selectors</a> <a href="#ref-for-typedef-extension-name②">(2)</a> <a href="#ref-for-typedef-extension-name③">(3)</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="custom-selector">
   <b><a href="#custom-selector">#custom-selector</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-custom-selector">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="at-ruledef-custom-selector">
   <b><a href="#at-ruledef-custom-selector">#at-ruledef-custom-selector</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-at-ruledef-custom-selector">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="typedef-custom-selector">
   <b><a href="#typedef-custom-selector">#typedef-custom-selector</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-custom-selector">3. 
Custom Selectors</a>
   </ul>
  </aside>
  <aside class="dfn-panel" data-for="typedef-custom-arg">
   <b><a href="#typedef-custom-arg">#typedef-custom-arg</a></b><b>Referenced in:</b>
   <ul>
    <li><a href="#ref-for-typedef-custom-arg">3. 
Custom Selectors</a> <a href="#ref-for-typedef-custom-arg①">(2)</a>
   </ul>
  </aside>
<script>/* script-dfn-panel */

document.body.addEventListener("click", function(e) {
    var queryAll = function(sel) { return [].slice.call(document.querySelectorAll(sel)); }
    // Find the dfn element or panel, if any, that was clicked on.
    var el = e.target;
    var target;
    var hitALink = false;
    while(el.parentElement) {
        if(el.tagName == "A") {
            // Clicking on a link in a <dfn> shouldn't summon the panel
            hitALink = true;
        }
        if(el.classList.contains("dfn-paneled")) {
            target = "dfn";
            break;
        }
        if(el.classList.contains("dfn-panel")) {
            target = "dfn-panel";
            break;
        }
        el = el.parentElement;
    }
    if(target != "dfn-panel") {
        // Turn off any currently "on" or "activated" panels.
        queryAll(".dfn-panel.on, .dfn-panel.activated").forEach(function(el){
            el.classList.remove("on");
            el.classList.remove("activated");
        });
    }
    if(target == "dfn" && !hitALink) {
        // open the panel
        var dfnPanel = document.querySelector(".dfn-panel[data-for='" + el.id + "']");
        if(dfnPanel) {
            dfnPanel.classList.add("on");
            var rect = el.getBoundingClientRect();
            dfnPanel.style.left = window.scrollX + rect.right + 5 + "px";
            dfnPanel.style.top = window.scrollY + rect.top + "px";
            var panelRect = dfnPanel.getBoundingClientRect();
            var panelWidth = panelRect.right - panelRect.left;
            if(panelRect.right > document.body.scrollWidth && (rect.left - (panelWidth + 5)) > 0) {
                // Reposition, because the panel is overflowing
                dfnPanel.style.left = window.scrollX + rect.left - (panelWidth + 5) + "px";
            }
        } else {
            console.log("Couldn't find .dfn-panel[data-for='" + el.id + "']");
        }
    } else if(target == "dfn-panel") {
        // Switch it to "activated" state, which pins it.
        el.classList.add("activated");
        el.style.left = null;
        el.style.top = null;
    }

});
</script>